package test_achieve.cs;

import constant.Constant;
import util.tools.CommonTools;
import cucumber.api.java.en.Given;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

/**
 * Created by chenkuo on 2017/7/9.
 */
public class LoginCs {
    WebDriver driver = new FirefoxDriver();
    @Given("^进入Cs登录界面$")
    public void 进入cs登录界面() throws Throwable {
        driver.get(Constant.CSLOGINURL);
        CommonTools.waitElementLoad(driver,"xpath","/html/body/div/div/div[2]/form/div[3]/div[2]/button");
    }

    @Given("^输入Cs账户名:(.+)$")
    public void 输入cs账户名( String Csuser) throws Throwable {
        WebElement csuser = driver.findElement(By.xpath("/html/body/div/div/div[2]/form/div[1]/div/input"));
        csuser.sendKeys(Csuser);
        WebElement cspassword = driver.findElement(By.xpath("/html/body/div/div/div[2]/form/div[2]/div/input"));
        cspassword.sendKeys(Constant.CSPASSWORD);
//        WebElement Verification = driver.findElement(By.xpath(""));//输入验证码
//        Verification.sendKeys();
        Thread.sleep(9000);//输入验证码
    }

    @Given("^点击Cs登录按钮$")
    public void 点击cs登录按钮() throws Throwable {
        WebElement Sign = driver.findElement(By.xpath("/html/body/div/div/div[2]/form/div[3]/div[2]/button"));//点击登录按钮
        Sign.click();
        driver.manage().window().maximize();//浏览器窗口最大化
        CommonTools.waitElementLoad(driver,"xpath","/html/body/div[1]/div[2]/div[2]/ul/li[7]/input");//等待搜索框出现
        System.out.println("已经找到了！！！！！");

           }

    @Given("^输入需要查询的订单号$")
    public void 输入需要查询的订单号() throws Throwable {
        WebElement search = driver.findElement(By.xpath("/html/body/div[1]/div[2]/div[2]/ul/li[7]/input"));//搜索框
//        search.sendKeys(Constant.OrderNumbuter);
        Thread.sleep(2000);
        search.sendKeys("TDH2017070517627519");//输入订单号

    }
    @Given("^进行查询操作$")
    public void 进行查询操作() throws Throwable {
        WebElement query = driver.findElement(By.xpath("/html/body/div[1]/div[2]/div[2]/ul/li[8]/button"));//点击查询
        query.click();
        Thread.sleep(5000);
    }
    @Given("^进入订单详情")
    public void 进入订单详情() throws Throwable {
        WebElement See = driver.findElement(By.xpath("(//a[contains(text(),'查看')])[3]"));//点击查询按钮
        See.click();
    }

    @Given("^获取收件密码$")
    public void 获取收件密码() throws Throwable {
        WebElement ReceivePassword = driver.findElement(By.partialLinkText("收件密码："));//收件密码
        System.out.println( ReceivePassword.getText());
        driver.quit();
    }

    @Given("^调试等待(\\d+)秒$")
    public void 调试等待秒(int arg0) throws Throwable {
        Thread.sleep(10000);
    }
}
